﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class products_detfrm4 : System.Web.UI.Page
    {
        // Fields

        public string member = "游客";
        public string members = "游客";
        public string pinmsg = "";

        // Methods
        private void Bind()
        {
            DataTable table = SQLAccess.GreatDs("select *  from DB_Comment  where proid=" + re.replace(base.Request.QueryString["pid"]) + "  order by updatetime desc").Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.pinmsg = this.pinmsg + "<table width='100%' border='0' cellspacing='0' cellpadding='10'>";
                    this.pinmsg = this.pinmsg + "<tr>";
                    DataTable table2 = SQLAccess.GreatDs("select * from DB_Member where memberid=" + row["memberid"].ToString() + " and isnull(flag,0)!=2 ").Tables[0];
                    if (table2.Rows.Count > 0)
                    {
                        this.member = table2.Rows[0]["memberlogin"].ToString();
                    }
                    string pinmsg = this.pinmsg;
                    this.pinmsg = pinmsg + "<td><span  class='y'><b>" + row["title"].ToString() + "</b> " + row["updatetime"].ToString() + "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + this.member + "为此商品评分：";
                    for (int i = 1; i <= Convert.ToInt32(row["score"]); i++)
                    {
                        this.pinmsg = this.pinmsg + "<img src='images/star.gif' />";
                    }
                    for (int j = 0; j < (5 - Convert.ToInt32(row["score"])); j++)
                    {
                        this.pinmsg = this.pinmsg + "<img src='images/star1.gif' />";
                    }
                    this.pinmsg = this.pinmsg + " <br/>" + row["content"].ToString() + "</td>";
                    this.pinmsg = this.pinmsg + "</tr>";
                    this.pinmsg = this.pinmsg + "<tr>";
                    this.pinmsg = this.pinmsg + "<td></td>";
                    this.pinmsg = this.pinmsg + "</tr>";
                    this.pinmsg = this.pinmsg + "<tr>";
                    if (table.Rows[0]["replay"].ToString() == "")
                    {
                        this.pinmsg = this.pinmsg + "<td><b>回复：</b> 暂未回复</td>";
                    }
                    else
                    {
                        string str4 = this.pinmsg;
                        this.pinmsg = str4 + "<td><b>回复：</b> " + table.Rows[0]["replay"].ToString() + " &nbsp;" + table.Rows[0]["replaytime"].ToString() + "</td>";
                    }
                    this.pinmsg = this.pinmsg + "</tr>";
                    this.pinmsg = this.pinmsg + "</table>";
                }
            }
            if (this.Session["username"] != null)
            {
                this.members = this.Session["username"].ToString();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string str;
            if (this.Session["memberid"] == null)
            {
                str = "0";
            }
            else
            {
                str = this.Session["memberid"].ToString();
            }
            SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_Comment (memberid,types,proid,ipadd,updatetime,content,title,score,languages) values (", str, ",1,", re.replace(base.Request.QueryString["pid"]), ",'", HttpContext.Current.Request.UserHostAddress, "','", DateTime.Now, "','", re.replace(base.Request.Form["content"]), "','", re.replace(base.Request.Form["title"]), "',", base.Request.Form["score"], ",1)" }));
            if (info.info1("", "shopisfig").ToString() == "1")
            {
                base.Response.Write("<script language='javascript'>alert('评论提交成功,要经过管理员审核才能显示！');window.location.href='products_detfrm4.aspx?pid=" + re.replace(base.Request.QueryString["pid"]) + "';</script>");
                base.Response.End();
            }
            else
            {
                base.Response.Write("<script language='javascript'>alert('评论提交成功！');window.location.href='products_detfrm4.aspx?pid=" + re.replace(base.Request.QueryString["pid"]) + "';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack && (base.Request.QueryString["pid"] != null))
            {
                this.Bind();
            }
        }


    }
}